function [flow_driven,discretionary] = ShekEtAl(F,delta_cash)

%%%% This function computes the flow-driven and non-flow driven (discretionary) trading components as in Shek et al.

flow_driven = zeros(length(F),1);
discretionary = zeros(length(F),1);
    
% case 1
i = find(delta_cash<=F & F<0);
flow_driven(i) = 0;
discretionary(i) = F(i) - delta_cash(i);
% case 2
i = find(F<delta_cash & delta_cash<=0);
flow_driven(i) = F(i) - delta_cash(i);
discretionary(i) = 0;
% case 3
i = find(F < 0  & delta_cash>  0);
flow_driven(i) = F(i);
discretionary(i) = -delta_cash(i);
% case 4
i = find(delta_cash < 0  & F>= 0);
flow_driven(i) = F(i);
discretionary(i) = -delta_cash(i);
% case 5
i = find(delta_cash >= 0  & F> delta_cash);
flow_driven(i) = F(i) - delta_cash(i);
discretionary(i) = 0;
% case 6
i = find(delta_cash > F & F>= 0);
flow_driven(i) = 0;
discretionary(i) = F(i)-delta_cash(i);


end

